﻿using System;
using System.Web.Mvc;
using UnitTestingAspNetMVC.Models;
using MvcContrib;

namespace UnitTestingAspNetMVC.Controllers
{
	[HandleError]
	public class HomeController : BaseController
	{
		public ActionResult Index()
		{
			ViewData["Message"] = "Welcome to ASP.NET MVC!";

			return View();
		}

		public ActionResult About()
		{
			return View();
		}

		public ActionResult Speaker()
		{
			return View(this.SpeakerInfo);
		}

		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult Speaker(string firstName, string lastName)
		{
			this.SpeakerInfo = new SpeakerInfo { FirstName = firstName, LastName = lastName };
			if (String.IsNullOrEmpty(firstName))
			{
				ModelState.AddModelError("firstName", "First Name is Reqiured.");
			}
			if (String.IsNullOrEmpty(lastName))
			{
				ModelState.AddModelError("lastName", "Last Name is Reqiured.");
			}

			if (ModelState.Count != 0)
			{
				return this.RedirectToAction(c => c.Speaker());
			}

			return this.RedirectToAction(c => c.SessionDetails());
		}

		public ActionResult SessionDetails()
		{
			return View();
		}
	}
}
